package zj.it.bhne.greendao.entity;

import org.greenrobot.greendao.DaoException;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.ToMany;

import java.util.ArrayList;
import java.util.List;

import zj.it.bhne.greendao.BooksDao;
import zj.it.bhne.greendao.DaoSession;
import zj.it.bhne.greendao.StudentsDao;

@Entity
public class Students {
    @ToMany(referencedJoinProperty = "sid")//指定与之关联的其他类的id
    private List<Books> booksList = new ArrayList<>();

    @Id
    private Long id;

    private Long tid;

    //学生姓名
    private String name;

    //学生年龄
    private int age;

    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;

    /** Used for active entity operations. */
    @Generated(hash = 998494339)
    private transient StudentsDao myDao;

    @Generated(hash = 1206662261)
    public Students(Long id, Long tid, String name, int age) {
        this.id = id;
        this.tid = tid;
        this.name = name;
        this.age = age;
    }

    @Generated(hash = 174834727)
    public Students() {
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getTid() {
        return this.tid;
    }

    public void setTid(Long tid) {
        this.tid = tid;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return this.age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 186287401)
    public List<Books> getBooksList() {
        if (booksList == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            BooksDao targetDao = daoSession.getBooksDao();
            List<Books> booksListNew = targetDao._queryStudents_BooksList(id);
            synchronized (this) {
                if (booksList == null) {
                    booksList = booksListNew;
                }
            }
        }
        return booksList;
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 1655386779)
    public synchronized void resetBooksList() {
        booksList = null;
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 194085185)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getStudentsDao() : null;
    }

}
